import React, { Component } from 'react';
import { connect } from 'react-redux';
import {bindActionCreators} from "redux";
import { CommonTable } from 'components';
import SearchList from './SearchList/SearchList';
import { blackReportAction , blackReportState } from './index';
import moment from "moment/moment";
import { axios } from 'utils';

class BlackReport extends Component {
    columns = [
        {
            title: '渠道ID',
            dataIndex: 'channelId',
            key: 'channelId'
        },
        {
            title: '中心免费黑名单(调用量/命中率)',
            dataIndex: 'text1',
            key: 'text1',
            render(text) {
                return text || 0;
            }
        },
        {
            title: '中心收费黑名单(调用量/命中率)',
            dataIndex: 'text2',
            key: 'text2',
            render(text) {
                return text || 0;
            }
        },
        {
            title: '内部黑名单(调用量/命中率)',
            dataIndex: 'text3',
            key: 'text3',
            render(text) {
                return text || 0;
            }
        },
        {
            title: '绿盟黑名单(调用量/命中率)',
            dataIndex: 'text4',
            key: 'text4',
            render(text) {
                return text || 0;
            }
        }
    ]
    constructor(props) {
        super(props);
        this.state = {};
        this.searchParams = {
            time: [moment(0, 'HH'), moment({hour: 23, minute: 59, seconds: 59})]
        };
    }

    convertParams = () => {
        const { time, channelId } = this.searchParams;
        const isArr = Array.isArray(time) && time.length > 0;
        const startTime = isArr ? time[0].format('YYYY-MM-DD') : '';
        const endTime = isArr ? time[1].format('YYYY-MM-DD') : '';
        return { channelId, startTime, endTime };
    }
    // handlePageChange = (info) => {
    //     const { current, pageSize } = info;
    //     const params = this.convertParams();
    //     const { getTableData } = this.props;
    //     getTableData({ pageNum: current, pageSize, ...params });
    // }
    handleSearch = (obj) => {
        const { getTableData } = this.props;
        this.searchParams = obj;
        const params = this.convertParams();
        getTableData({ ...params });
    }
    componentDidMount() {
        const { getTableData, getSourceData } = this.props;
        const params = this.convertParams();
        getTableData({ ...params });
        getSourceData({ pageSize: 10000, pageNum: 1 });

        axios({
            url: '/hs/admin/orderOverdue/getDisPerOrGroup',
            method: 'post',
        }).then((res) =>{
            console.log("res=>",res)
        } )
    }

    render() {
        const { tableData: { data, pagination }, loading, sourceData } = this.props;
        return (
            <div>
                <SearchList handleSearch={this.handleSearch} initTime={this.searchParams.time} sourceData={sourceData}/>
                <CommonTable
                    columns={this.columns}
                    handlePageChange={this.handlePageChange}
                    dataSource={data}
                    pagination={null}
                    loading={loading}
                />
            </div>
        );
    }
}

const mapStateToProps = (state) => {
    const { businessStatisticsState: { blackReportState } } = state;
    return {
        tableData: blackReportState['data'],
        loading: blackReportState['loading'],
        sourceData: blackReportState['sourceData']
    }
}
const mapDispatchToProps = (dispatch) => {
    return bindActionCreators({
        getTableData: blackReportAction.brGetTableData,
        getSourceData: blackReportAction.brGetSourceData
    },dispatch)
}

export default connect(mapStateToProps, mapDispatchToProps)(BlackReport);